//
//  CommentCell.m
//  BookRank
//
//  Created by wststar on 14-3-2.
//  Copyright (c) 2014年 wststar. All rights reserved.
//

#import "CommentCell.h"
#import "RTLabel.h"
#import "UserModel.h"
#import "CommentModel.h"
#import "UIImageView+WebCache.h"
#import "UIUtils.h"

@implementation CommentCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

+(float)getCommentHeight:(CommentModel *) commentModel{
    RTLabel * rt = [[[RTLabel alloc]initWithFrame:CGRectMake(0, 0, 240, 0)]autorelease];
    rt.font = [UIFont systemFontOfSize:14.0];
    rt.text = commentModel.text;
    return rt.optimumSize.height;
}

-(void)layoutSubviews{
    NSString * urlStriing =  self.commentModel.user.profile_image_url;
    [_userImage setImageWithURL:[NSURL URLWithString:urlStriing]];
    
    _nickLabel.text = self.commentModel.user.screen_name;
    _timeLabel.text = [UIUtils fomateString:self.commentModel.created_at];
    
    _contentLabel.text = self.commentModel.text;
    _contentLabel.height = _contentLabel.optimumSize.height;
    
}

-(void)awakeFromNib{
    _userImage = [(UIImageView *)[self viewWithTag:100]autorelease];
    _nickLabel = [(UILabel *)[self viewWithTag:101]autorelease];
    _timeLabel = [(UILabel *)[self viewWithTag:102]autorelease];
    
    _contentLabel = [[[RTLabel alloc]initWithFrame:CGRectMake(_userImage.right+10, _nickLabel.bottom+5, 240, 25)]autorelease] ;
    _contentLabel.font = [UIFont systemFontOfSize:14.0];
    [_contentLabel setLinkAttributes:[NSDictionary dictionaryWithObject:@"#4595CB" forKey:@"color"]];
    [_contentLabel setSelectedLinkAttributes:[NSDictionary dictionaryWithObject:@"darkGray" forKey:@"color"]];
    [self.contentView addSubview:_contentLabel];
}

#pragma mark --RTlabelDelegate
- (void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL*)url{

}

@end
